/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FiltrosFrame.java
 *
 * Created on 17/07/2010, 19:14:46
 */
package user_gui;

import core.FiltraLigacao;
import elemento.Empresa;
import java.awt.HeadlessException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.ListModel;
import op.ContaTelefonica;
import op.Ligacao;
import op.Telefone;
import op.Utils;
import op.filtros.FiltraCelularOuFixo;
import op.filtros.FiltraPorDDD;
import op.filtros.FiltraPorData;
import op.filtros.FiltraPorDestino;
import op.filtros.FiltraPorDuracao;
import op.filtros.FiltraPorEmpresa;
import op.filtros.FiltraPorHora;
import op.filtros.FiltraPorOrigem;
import op.filtros.FiltraPorTipo;

/**
 *
 * @author Jônatas
 */
public class FiltrosFrame extends javax.swing.JFrame {

    private FramePrincipal parentComponent;

    /** Creates new form FiltrosFrame */
    public FiltrosFrame(FramePrincipal parentComponent, ContaTelefonica contaOriginal) throws HeadlessException {
        this.parentComponent = parentComponent;
        this.parentComponent.setEnabled(false);
        initComponents();
        disableAll();

        fillTelefones(contaOriginal);
        fillTipos(contaOriginal);
        fillDDDs(contaOriginal);
        fillEmpresas();

    }

    private void fillDDDs(ContaTelefonica contaOriginal) {
        if (contaOriginal == null) {
            return;
        }

        for (Ligacao lig : contaOriginal.getLigacoes()) {

            Telefone destino = lig.getDestino();

            if (destino != null && !destino.isDiferente()) {
                String ddd = destino.getDdd();
                if (!dddsFora.contains(ddd)) {
                    dddsFora.add(ddd);
                }
            }
        }

        updateListDDDsFora();
    }

    private void fillTipos(ContaTelefonica contaOriginal) {
        if (contaOriginal == null) {
            return;
        }

        for (Ligacao lig : contaOriginal.getLigacoes()) {
            String tipo = lig.getTipoDeLigacao();

            if (!tiposFora.contains(tipo)) {
                tiposFora.add(tipo);
            }
        }

        updateListTiposFora();

    }

    private void fillTelefones(ContaTelefonica contaOriginal) {

        if (contaOriginal == null) {
            return;
        }

        Date inicio = null;
        Date fim = null;

        for (Ligacao lig : contaOriginal.getLigacoes()) {
            Telefone tel = lig.getNumeroDeOrigem();
            Date dataLig = lig.getDataOrigemLigacao();

            if (dataLig != null) {
                if (inicio == null && fim == null) {
                    inicio = dataLig;
                    fim = dataLig;
                } else if (inicio.compareTo(dataLig) > 0) {
                    inicio = dataLig;
                } else if (fim.compareTo(dataLig) < 0) {
                    fim = dataLig;
                }
            }

            String key = tel.toString();

            Telefone destino = lig.getDestino();

            if (!destinoFora.containsKey(destino.toString())) {
                destinoFora.put(destino.toString(), destino);
            }

            if (telefonesFora.containsKey(key)) {
                continue;
            }

            telefonesFora.put(key, tel);
        }

        if (inicio != null) {
            inicioDateChooser.setDate(inicio);
        }

        if (fim != null) {
            fimDateChooser.setDate(fim);
        }

        updateListFora();
        updateListDestinoFora();

    }

    private void updateListDestinoFora() {
        ListModel model = new MapBasedListModel(destinoFora);
        destinoForaJList.setModel(model);
    }

    private void updateListDestinoDentro() {
        ListModel model = new MapBasedListModel(destinoDentro);
        destinoDentroJList.setModel(model);
    }

    private void updateListDDDsFora() {
        ListModel model = new SetBasedListModel(dddsFora);
        dddsForaJList.setModel(model);
    }

    private void updateListDDDsDentro() {
        ListModel model = new SetBasedListModel(dddsDentro);
        dddsDentroJList.setModel(model);
    }

    private void updateListTiposFora() {
        ListModel model = new SetBasedListModel(tiposFora);
        tiposForaJList.setModel(model);
    }

    private void updateListTiposDentro() {
        ListModel model = new SetBasedListModel(tiposDentro);
        tiposDentroJList.setModel(model);
    }

    private void updateListFora() {
        ListModel model = new MapBasedListModel(telefonesFora);
        telefonesForaJList.setModel(model);
    }

    private void updateListDentro() {
        ListModel model = new MapBasedListModel(telefonesDentro);
        telefonesDentroJList.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupCelFixo = new javax.swing.ButtonGroup();
        okButton = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        comboBoxSegundoDuracaoFim = new javax.swing.JComboBox();
        duracaoCheckBox = new javax.swing.JCheckBox();
        fimDateChooser = new com.toedter.calendar.JDateChooser(new Date());
        inicioDateChooser = new com.toedter.calendar.JDateChooser(new Date());
        jLabel14 = new javax.swing.JLabel();
        dataCheckBox = new javax.swing.JCheckBox();
        jLabel11 = new javax.swing.JLabel();
        horaCheckBox = new javax.swing.JCheckBox();
        comboBoxMinutoFim = new javax.swing.JComboBox();
        comboBoxSegundoDuracaoInicio = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        comboBoxHoraFim = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        comboBoxMinutoInicio = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        comboBoxHoraInicio = new javax.swing.JComboBox();
        comboBoxMinutoDuracaoInicio = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        comboBoxMinutoDuracaoFim = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        comboBoxHoraDuracaoInicio = new javax.swing.JComboBox();
        comboBoxHoraDuracaoFim = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        insereDestinoButton = new javax.swing.JButton();
        telefoneCheckBox = new javax.swing.JCheckBox();
        removeTelefoneButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        telefonesDentroJList = new javax.swing.JList();
        destinoCheckBox = new javax.swing.JCheckBox();
        insereTelefoneButton = new javax.swing.JButton();
        removeDestinoButton = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        destinoForaJList = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        telefonesForaJList = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        destinoDentroJList = new javax.swing.JList();
        jPanel3 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tiposForaJList = new javax.swing.JList();
        insereTipoButton = new javax.swing.JButton();
        removeTipoButton = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        tiposDentroJList = new javax.swing.JList();
        tipoCheckBox = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        radioCel = new javax.swing.JRadioButton();
        radioFixo = new javax.swing.JRadioButton();
        checkBoxCelFixo = new javax.swing.JCheckBox();
        jPanel4 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        dddCheckBox = new javax.swing.JCheckBox();
        jScrollPane7 = new javax.swing.JScrollPane();
        dddsDentroJList = new javax.swing.JList();
        insereDDDButton = new javax.swing.JButton();
        removeDDDButton = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        dddsForaJList = new javax.swing.JList();
        jPanel5 = new javax.swing.JPanel();
        cbEmpresaOrigem = new javax.swing.JCheckBox();
        jLabel23 = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        listGrupoOrigemFora = new javax.swing.JList();
        jScrollPane11 = new javax.swing.JScrollPane();
        listGrupoOrigemDentro = new javax.swing.JList();
        buttonInsereGrupoOrigem = new javax.swing.JButton();
        buttonRemoveGrupoOrigem = new javax.swing.JButton();
        cbEmpresaDestino = new javax.swing.JCheckBox();
        jScrollPane12 = new javax.swing.JScrollPane();
        listGrupoDestinoDentro = new javax.swing.JList();
        buttonInsereGrupoDestino = new javax.swing.JButton();
        buttonRemoveGrupoDestino = new javax.swing.JButton();
        jScrollPane13 = new javax.swing.JScrollPane();
        listGrupoDestinoFora = new javax.swing.JList();
        jLabel24 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Filtros");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        okButton.setText("OK");
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        jLabel20.setText(":");

        comboBoxSegundoDuracaoFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        duracaoCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                duracaoCheckBoxActionPerformed(evt);
            }
        });

        jLabel14.setText("Filtro por data:");

        dataCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataCheckBoxActionPerformed(evt);
            }
        });

        jLabel11.setText("até");

        horaCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                horaCheckBoxActionPerformed(evt);
            }
        });

        comboBoxMinutoFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        comboBoxSegundoDuracaoInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        jLabel10.setText(":");

        jLabel8.setText(":");

        jLabel19.setText(":");

        comboBoxHoraFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));

        jLabel9.setText("até");

        jLabel12.setText("até");

        comboBoxMinutoInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        jLabel13.setText(":");

        comboBoxHoraInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));

        comboBoxMinutoDuracaoInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        jLabel7.setText("Filtro por hora:");

        comboBoxMinutoDuracaoFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" }));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel2.setText("(Deixe 00:00:00 para não utilizar)");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 9));
        jLabel3.setText("Formato:");

        comboBoxHoraDuracaoInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));

        comboBoxHoraDuracaoFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23" }));

        jLabel18.setText(":");

        jLabel17.setText("Filtro por duração:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel17))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBoxHoraDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBoxMinutoDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBoxSegundoDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addGap(10, 10, 10)
                                .addComponent(comboBoxHoraDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBoxMinutoDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBoxSegundoDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                            .addComponent(dataCheckBox)
                            .addComponent(duracaoCheckBox)
                            .addComponent(horaCheckBox)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(comboBoxHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboBoxMinutoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(comboBoxHoraFim, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboBoxMinutoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(inicioDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(fimDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel14)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(95, 95, 95)
                        .addComponent(jLabel2)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(comboBoxHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(horaCheckBox)
                    .addComponent(comboBoxHoraFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addComponent(comboBoxMinutoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboBoxMinutoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(28, 28, 28)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel14)
                    .addComponent(fimDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(inicioDateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(dataCheckBox))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLabel12)
                    .addComponent(jLabel13)
                    .addComponent(comboBoxHoraDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboBoxHoraDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(comboBoxMinutoDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboBoxMinutoDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20)
                    .addComponent(comboBoxSegundoDuracaoInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(comboBoxSegundoDuracaoFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(duracaoCheckBox)
                    .addComponent(jLabel17))
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addContainerGap(269, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Filtros por Tempo", jPanel1);

        jLabel16.setText("Filtro por telefone destino:");

        insereDestinoButton.setText(">>");
        insereDestinoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insereDestinoButtonActionPerformed(evt);
            }
        });

        telefoneCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telefoneCheckBoxActionPerformed(evt);
            }
        });

        removeTelefoneButton.setText("<<");
        removeTelefoneButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeTelefoneButtonActionPerformed(evt);
            }
        });

        telefonesDentroJList.setToolTipText("Números Selecionados");
        jScrollPane2.setViewportView(telefonesDentroJList);

        destinoCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                destinoCheckBoxActionPerformed(evt);
            }
        });

        insereTelefoneButton.setText(">>");
        insereTelefoneButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insereTelefoneButtonActionPerformed(evt);
            }
        });

        removeDestinoButton.setText("<<");
        removeDestinoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDestinoButtonActionPerformed(evt);
            }
        });

        jLabel15.setText("Filtro por telefone:");

        jScrollPane3.setViewportView(destinoForaJList);

        jScrollPane1.setViewportView(telefonesForaJList);

        destinoDentroJList.setToolTipText("Números Selecionados");
        jScrollPane4.setViewportView(destinoDentroJList);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(removeTelefoneButton)
                            .addComponent(insereTelefoneButton)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(removeDestinoButton)
                            .addComponent(insereDestinoButton))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(telefoneCheckBox, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(destinoCheckBox, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(78, 78, 78))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel16)
                .addContainerGap(311, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel15)
                .addContainerGap(349, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane1, jScrollPane2, jScrollPane4});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(telefoneCheckBox)
                        .addGap(30, 30, 30)
                        .addComponent(insereTelefoneButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeTelefoneButton))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane2)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(destinoCheckBox)
                        .addGap(30, 30, 30)
                        .addComponent(insereDestinoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeDestinoButton))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel16)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE))))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane1, jScrollPane2, jScrollPane4});

        jTabbedPane1.addTab("Filtros por Telefone", jPanel2);

        jLabel21.setText("Filtro por tipo:");

        jScrollPane5.setViewportView(tiposForaJList);

        insereTipoButton.setText(">>");
        insereTipoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insereTipoButtonActionPerformed(evt);
            }
        });

        removeTipoButton.setText("<<");
        removeTipoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeTipoButtonActionPerformed(evt);
            }
        });

        tiposDentroJList.setToolTipText("Números Selecionados");
        jScrollPane6.setViewportView(tiposDentroJList);

        tipoCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tipoCheckBoxActionPerformed(evt);
            }
        });

        jLabel1.setText("Ligações para Celular/Fixo:");

        buttonGroupCelFixo.add(radioCel);
        radioCel.setSelected(true);
        radioCel.setText("Apenas Celular");

        buttonGroupCelFixo.add(radioFixo);
        radioFixo.setText("Apenas Fixo");

        checkBoxCelFixo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxCelFixoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addContainerGap(371, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(radioCel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(radioFixo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(checkBoxCelFixo))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(removeTipoButton)
                                    .addComponent(insereTipoButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tipoCheckBox)))
                        .addGap(54, 54, 54))))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane5, jScrollPane6});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(tipoCheckBox)
                        .addGap(30, 30, 30)
                        .addComponent(insereTipoButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeTipoButton))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(radioCel)
                    .addComponent(radioFixo)
                    .addComponent(checkBoxCelFixo))
                .addContainerGap(161, Short.MAX_VALUE))
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jScrollPane5, jScrollPane6});

        jTabbedPane1.addTab("Filtros por Tipo", jPanel3);

        jLabel22.setText("Filtro por DDD:");

        dddCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dddCheckBoxActionPerformed(evt);
            }
        });

        dddsDentroJList.setToolTipText("Números Selecionados");
        jScrollPane7.setViewportView(dddsDentroJList);

        insereDDDButton.setText(">>");
        insereDDDButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insereDDDButtonActionPerformed(evt);
            }
        });

        removeDDDButton.setText("<<");
        removeDDDButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDDDButtonActionPerformed(evt);
            }
        });

        jScrollPane8.setViewportView(dddsForaJList);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 360, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(removeDDDButton)
                            .addComponent(insereDDDButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dddCheckBox)))
                .addContainerGap(8, Short.MAX_VALUE))
        );

        jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jScrollPane7, jScrollPane8});

        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(dddCheckBox)
                        .addGap(30, 30, 30)
                        .addComponent(insereDDDButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(removeDDDButton))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane7)
                            .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))))
                .addContainerGap(191, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Filtros por DDD", jPanel4);

        cbEmpresaOrigem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEmpresaOrigemActionPerformed(evt);
            }
        });

        jLabel23.setText("Filtro por Grupo de origem:");

        jScrollPane10.setViewportView(listGrupoOrigemFora);

        listGrupoOrigemDentro.setToolTipText("Números Selecionados");
        jScrollPane11.setViewportView(listGrupoOrigemDentro);

        buttonInsereGrupoOrigem.setText(">>");
        buttonInsereGrupoOrigem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonInsereGrupoOrigemActionPerformed(evt);
            }
        });

        buttonRemoveGrupoOrigem.setText("<<");
        buttonRemoveGrupoOrigem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRemoveGrupoOrigemActionPerformed(evt);
            }
        });

        cbEmpresaDestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbEmpresaDestinoActionPerformed(evt);
            }
        });

        listGrupoDestinoDentro.setToolTipText("Números Selecionados");
        jScrollPane12.setViewportView(listGrupoDestinoDentro);

        buttonInsereGrupoDestino.setText(">>");
        buttonInsereGrupoDestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonInsereGrupoDestinoActionPerformed(evt);
            }
        });

        buttonRemoveGrupoDestino.setText("<<");
        buttonRemoveGrupoDestino.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonRemoveGrupoDestinoActionPerformed(evt);
            }
        });

        jScrollPane13.setViewportView(listGrupoDestinoFora);

        jLabel24.setText("Filtro por Grupo de destino:");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(buttonRemoveGrupoOrigem)
                                    .addComponent(buttonInsereGrupoOrigem)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                                .addComponent(jScrollPane13, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(buttonRemoveGrupoDestino)
                                    .addComponent(buttonInsereGrupoDestino))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbEmpresaOrigem, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cbEmpresaDestino, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 292, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 295, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(13, 13, 13))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(cbEmpresaOrigem)
                        .addGap(30, 30, 30)
                        .addComponent(buttonInsereGrupoOrigem)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonRemoveGrupoOrigem))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel23)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane11)
                            .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(cbEmpresaDestino)
                        .addGap(30, 30, 30)
                        .addComponent(buttonInsereGrupoDestino)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonRemoveGrupoDestino))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane13, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                            .addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE))))
                .addGap(11, 11, 11))
        );

        jTabbedPane1.addTab("Filtro por Grupo", jPanel5);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(417, Short.MAX_VALUE)
                .addComponent(okButton)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 454, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(okButton)
                .addGap(18, 18, 18))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-490)/2, (screenSize.height-552)/2, 490, 552);
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.parentComponent.setEnabled(true);
    }//GEN-LAST:event_formWindowClosing

    private void disableAll() {
        comboBoxHoraInicio.setEnabled(false);
        comboBoxHoraFim.setEnabled(false);
        comboBoxMinutoInicio.setEnabled(false);
        comboBoxMinutoFim.setEnabled(false);
        inicioDateChooser.setEnabled(false);
        fimDateChooser.setEnabled(false);
        telefonesDentroJList.setEnabled(false);
        telefonesForaJList.setEnabled(false);
        insereTelefoneButton.setEnabled(false);
        removeTelefoneButton.setEnabled(false);
        comboBoxHoraDuracaoInicio.setEnabled(false);
        comboBoxHoraDuracaoFim.setEnabled(false);
        comboBoxMinutoDuracaoFim.setEnabled(false);
        comboBoxMinutoDuracaoInicio.setEnabled(false);
        comboBoxSegundoDuracaoInicio.setEnabled(false);
        comboBoxSegundoDuracaoFim.setEnabled(false);
        destinoDentroJList.setEnabled(false);
        destinoForaJList.setEnabled(false);
        insereDestinoButton.setEnabled(false);
        removeDestinoButton.setEnabled(false);
        tiposDentroJList.setEnabled(false);
        tiposForaJList.setEnabled(false);
        insereTipoButton.setEnabled(false);
        removeTipoButton.setEnabled(false);
        radioCel.setEnabled(false);
        radioFixo.setEnabled(false);
        dddsDentroJList.setEnabled(false);
        dddsForaJList.setEnabled(false);
        insereDDDButton.setEnabled(false);
        removeDDDButton.setEnabled(false);
        listGrupoDestinoDentro.setEnabled(false);
        listGrupoDestinoFora.setEnabled(false);
        buttonInsereGrupoDestino.setEnabled(false);
        buttonRemoveGrupoDestino.setEnabled(false);
        listGrupoOrigemDentro.setEnabled(false);
        listGrupoOrigemFora.setEnabled(false);
        buttonInsereGrupoOrigem.setEnabled(false);
        buttonRemoveGrupoOrigem.setEnabled(false);
    }

    private void horaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_horaCheckBoxActionPerformed

        if (horaCheckBox.isSelected()) {
            comboBoxHoraInicio.setEnabled(true);
            comboBoxHoraFim.setEnabled(true);
            comboBoxMinutoInicio.setEnabled(true);
            comboBoxMinutoFim.setEnabled(true);
        } else {
            comboBoxHoraInicio.setEnabled(false);
            comboBoxHoraFim.setEnabled(false);
            comboBoxMinutoInicio.setEnabled(false);
            comboBoxMinutoFim.setEnabled(false);
        }

    }//GEN-LAST:event_horaCheckBoxActionPerformed

    private void dataCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataCheckBoxActionPerformed
        if (dataCheckBox.isSelected()) {
            inicioDateChooser.setEnabled(true);
            fimDateChooser.setEnabled(true);
        } else {
            inicioDateChooser.setEnabled(false);
            fimDateChooser.setEnabled(false);
        }
    }//GEN-LAST:event_dataCheckBoxActionPerformed

    private void telefoneCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telefoneCheckBoxActionPerformed

        if (telefoneCheckBox.isSelected()) {
            telefonesDentroJList.setEnabled(true);
            telefonesForaJList.setEnabled(true);
            insereTelefoneButton.setEnabled(true);
            removeTelefoneButton.setEnabled(true);
        } else {
            telefonesDentroJList.setEnabled(false);
            telefonesForaJList.setEnabled(false);
            insereTelefoneButton.setEnabled(false);
            removeTelefoneButton.setEnabled(false);
        }

    }//GEN-LAST:event_telefoneCheckBoxActionPerformed

    private void removeEmpresaList1InsereList2(javax.swing.JList listRemove, Map<String, Empresa> mapRemove,
            Map<String, Empresa> mapInsere) {
        Object[] foraSelecionados = listRemove.getSelectedValues();

        for (Object obj : foraSelecionados) {
            Empresa rem = mapRemove.remove((String) obj);
            mapInsere.put((String) obj, rem);
        }
    }

    private void removeList1InsereList2(javax.swing.JList listRemove, Map<String, Telefone> mapRemove,
            Map<String, Telefone> mapInsere) {
        Object[] foraSelecionados = listRemove.getSelectedValues();

        for (Object obj : foraSelecionados) {
            Telefone tel = mapRemove.remove((String) obj);
            mapInsere.put((String) obj, tel);
        }
    }

    private void removeList1InsereList2(javax.swing.JList listRemove, Set<String> setRemove,
            Set<String> setInsere) {
        Object[] foraSelecionados = listRemove.getSelectedValues();

        for (Object obj : foraSelecionados) {
            setRemove.remove(obj.toString());
            setInsere.add(obj.toString());
        }
    }

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed

        if (this.telefonesDentro.isEmpty() && this.telefonesFora.isEmpty()) {
            this.parentComponent.setEnabled(true);
            dispose();
        }

        List<FiltraLigacao> filtros = new ArrayList<FiltraLigacao>();

        if (dddCheckBox.isSelected()) {
            if (!dddsDentro.isEmpty()) {
                filtros.add(new FiltraPorDDD(dddsDentro));
            }
        }

        if (cbEmpresaOrigem.isSelected()) {
            FiltraLigacao filtro = new FiltraPorEmpresa(empresaOrigemDentro.values(), FiltraPorEmpresa.OrigemDestino.ORIGEM);
            if (filtro != null) {
                filtros.add(filtro);
            }
        }

        if (cbEmpresaDestino.isSelected()) {
            FiltraLigacao filtro = new FiltraPorEmpresa(empresaDestinoDentro.values(), FiltraPorEmpresa.OrigemDestino.DESTINO);
            if (filtro != null) {
                filtros.add(filtro);
            }
        }

        if (checkBoxCelFixo.isSelected()) {

            FiltraLigacao filtro = null;

            if (radioCel.isSelected()) {
                filtro = new FiltraCelularOuFixo(FiltraCelularOuFixo.TipoFiltro.CELULAR);
            } else {
                filtro = new FiltraCelularOuFixo(FiltraCelularOuFixo.TipoFiltro.FIXO);
            }

            filtros.add(filtro);

        }

        if (horaCheckBox.isSelected()) {

            int horaInicio = Integer.parseInt(comboBoxHoraInicio.getSelectedItem().toString());
            int minutoInicio = Integer.parseInt(comboBoxMinutoInicio.getSelectedItem().toString());
            int horaFim = Integer.parseInt(comboBoxHoraFim.getSelectedItem().toString());
            int minutoFim = Integer.parseInt(comboBoxMinutoFim.getSelectedItem().toString());

            filtros.add(new FiltraPorHora(horaInicio, minutoInicio, horaFim, minutoFim));

        }

        if (dataCheckBox.isSelected()) {
            Date inicio = inicioDateChooser.getDate();
            Date fim = fimDateChooser.getDate();

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(inicio);

            int anoInicio = calendar.get(Calendar.YEAR);
            int mesInicio = calendar.get(Calendar.MONTH);
            int diaInicio = calendar.get(Calendar.DATE);

            calendar = Calendar.getInstance();
            calendar.set(anoInicio, mesInicio, diaInicio);

            inicio = calendar.getTime();

            calendar = Calendar.getInstance();
            calendar.setTime(fim);

            int anoFim = calendar.get(Calendar.YEAR);
            int mesFim = calendar.get(Calendar.MONTH);
            int diaFim = calendar.get(Calendar.DATE);

            calendar = Calendar.getInstance();
            calendar.set(anoFim, mesFim, diaFim);

            fim = calendar.getTime();

            if (fim.compareTo(inicio) < 0) {
                JOptionPane.showMessageDialog(this, "A data final não deve ser anterior à inicial.",
                        "Erro", JOptionPane.ERROR_MESSAGE);
                return;
            }

            filtros.add(new FiltraPorData(inicio, fim));
        }

        if (telefoneCheckBox.isSelected()) {
            Set<Telefone> telefones = new HashSet<Telefone>();
            for (String key : telefonesDentro.keySet()) {
                telefones.add(telefonesDentro.get(key));
            }

            filtros.add(new FiltraPorOrigem(telefones));

        }

        if (destinoCheckBox.isSelected()) {
            Set<Telefone> telefones = new HashSet<Telefone>();
            for (String key : destinoDentro.keySet()) {
                telefones.add(destinoDentro.get(key));
            }

            filtros.add(new FiltraPorDestino(telefones));

        }

        if (tipoCheckBox.isSelected()) {
            if (!tiposDentro.isEmpty()) {
                filtros.add(new FiltraPorTipo(tiposDentro));
            }
        }

        if (duracaoCheckBox.isSelected()) {
            try {

                int horaInicio = Integer.parseInt(comboBoxHoraDuracaoInicio.getSelectedItem().toString());
                int minutoInicio = Integer.parseInt(comboBoxMinutoDuracaoInicio.getSelectedItem().toString());
                int segundoInicio = Integer.parseInt(comboBoxSegundoDuracaoInicio.getSelectedItem().toString());
                int horaFim = Integer.parseInt(comboBoxHoraDuracaoFim.getSelectedItem().toString());
                int minutoFim = Integer.parseInt(comboBoxMinutoDuracaoFim.getSelectedItem().toString());
                int segundoFim = Integer.parseInt(comboBoxSegundoDuracaoFim.getSelectedItem().toString());

                long inicioSegundos = getDuracaoSegundos(horaInicio, minutoInicio, segundoInicio);


                long fimSegundos = getDuracaoSegundos(horaFim, minutoFim, segundoFim);


                if (fimSegundos > 0 && fimSegundos < inicioSegundos) {
                    JOptionPane.showMessageDialog(this, "Preencha os campos de duração corretamente.",
                            "Erro", JOptionPane.ERROR_MESSAGE);
                    return;
                }

                filtros.add(new FiltraPorDuracao(inicioSegundos, fimSegundos));

            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Preencha os campos de duração corretamente.",
                        "Erro", JOptionPane.ERROR_MESSAGE);
                return;
            }
        }

        this.parentComponent.setConta(Utils.aplicaFiltros(
                this.parentComponent.getContaOriginal(), filtros));

        this.parentComponent.setEnabled(true);

        this.dispose();

    }//GEN-LAST:event_okButtonActionPerformed

    private void insereTelefoneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insereTelefoneButtonActionPerformed
        removeList1InsereList2(telefonesForaJList, telefonesFora, telefonesDentro);
        updateListFora();
        updateListDentro();
    }//GEN-LAST:event_insereTelefoneButtonActionPerformed

    private void removeTelefoneButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTelefoneButtonActionPerformed
        removeList1InsereList2(telefonesDentroJList, telefonesDentro, telefonesFora);
        updateListFora();
        updateListDentro();
    }//GEN-LAST:event_removeTelefoneButtonActionPerformed

    private void duracaoCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duracaoCheckBoxActionPerformed
        if (duracaoCheckBox.isSelected()) {
            comboBoxHoraDuracaoInicio.setEnabled(true);
            comboBoxHoraDuracaoFim.setEnabled(true);
            comboBoxMinutoDuracaoFim.setEnabled(true);
            comboBoxMinutoDuracaoInicio.setEnabled(true);
            comboBoxSegundoDuracaoInicio.setEnabled(true);
            comboBoxSegundoDuracaoFim.setEnabled(true);
        } else {
            comboBoxHoraDuracaoInicio.setEnabled(false);
            comboBoxHoraDuracaoFim.setEnabled(false);
            comboBoxMinutoDuracaoFim.setEnabled(false);
            comboBoxMinutoDuracaoInicio.setEnabled(false);
            comboBoxSegundoDuracaoInicio.setEnabled(false);
            comboBoxSegundoDuracaoFim.setEnabled(false);
        }
    }//GEN-LAST:event_duracaoCheckBoxActionPerformed

    private void insereDestinoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insereDestinoButtonActionPerformed
        removeList1InsereList2(destinoForaJList, destinoFora, destinoDentro);
        updateListDestinoDentro();
        updateListDestinoFora();
    }//GEN-LAST:event_insereDestinoButtonActionPerformed

    private void removeDestinoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDestinoButtonActionPerformed
        removeList1InsereList2(destinoDentroJList, destinoDentro, destinoFora);
        updateListDestinoDentro();
        updateListDestinoFora();
    }//GEN-LAST:event_removeDestinoButtonActionPerformed

    private void destinoCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_destinoCheckBoxActionPerformed
        if (destinoCheckBox.isSelected()) {
            destinoDentroJList.setEnabled(true);
            destinoForaJList.setEnabled(true);
            insereDestinoButton.setEnabled(true);
            removeDestinoButton.setEnabled(true);
        } else {
            destinoDentroJList.setEnabled(false);
            destinoForaJList.setEnabled(false);
            insereDestinoButton.setEnabled(false);
            removeDestinoButton.setEnabled(false);
        }
    }//GEN-LAST:event_destinoCheckBoxActionPerformed

    private void insereTipoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insereTipoButtonActionPerformed
        removeList1InsereList2(tiposForaJList, tiposFora, tiposDentro);
        updateListTiposDentro();
        updateListTiposFora();
    }//GEN-LAST:event_insereTipoButtonActionPerformed

    private void removeTipoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTipoButtonActionPerformed
        removeList1InsereList2(tiposDentroJList, tiposDentro, tiposFora);
        updateListTiposDentro();
        updateListTiposFora();
    }//GEN-LAST:event_removeTipoButtonActionPerformed

    private void tipoCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tipoCheckBoxActionPerformed
        if (tipoCheckBox.isSelected()) {
            tiposDentroJList.setEnabled(true);
            tiposForaJList.setEnabled(true);
            insereTipoButton.setEnabled(true);
            removeTipoButton.setEnabled(true);
        } else {
            tiposDentroJList.setEnabled(false);
            tiposForaJList.setEnabled(false);
            insereTipoButton.setEnabled(false);
            removeTipoButton.setEnabled(false);
        }
    }//GEN-LAST:event_tipoCheckBoxActionPerformed

    private void checkBoxCelFixoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxCelFixoActionPerformed
        if (checkBoxCelFixo.isSelected()) {
            radioCel.setEnabled(true);
            radioFixo.setEnabled(true);
        } else {
            radioCel.setEnabled(false);
            radioFixo.setEnabled(false);
        }
    }//GEN-LAST:event_checkBoxCelFixoActionPerformed

    private void dddCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dddCheckBoxActionPerformed
        if (dddCheckBox.isSelected()) {
            dddsDentroJList.setEnabled(true);
            dddsForaJList.setEnabled(true);
            insereDDDButton.setEnabled(true);
            removeDDDButton.setEnabled(true);
        } else {
            dddsDentroJList.setEnabled(false);
            dddsForaJList.setEnabled(false);
            insereDDDButton.setEnabled(false);
            removeDDDButton.setEnabled(false);
        }
    }//GEN-LAST:event_dddCheckBoxActionPerformed

    private void insereDDDButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insereDDDButtonActionPerformed
        removeList1InsereList2(dddsForaJList, dddsFora, dddsDentro);
        updateListDDDsDentro();
        updateListDDDsFora();
    }//GEN-LAST:event_insereDDDButtonActionPerformed

    private void removeDDDButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDDDButtonActionPerformed
        removeList1InsereList2(dddsDentroJList, dddsDentro, dddsFora);
        updateListDDDsDentro();
        updateListDDDsFora();
    }//GEN-LAST:event_removeDDDButtonActionPerformed

    private void cbEmpresaOrigemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEmpresaOrigemActionPerformed
        if (cbEmpresaOrigem.isSelected()) {
            listGrupoOrigemDentro.setEnabled(true);
            listGrupoOrigemFora.setEnabled(true);
            buttonInsereGrupoOrigem.setEnabled(true);
            buttonRemoveGrupoOrigem.setEnabled(true);
        } else {
            listGrupoOrigemDentro.setEnabled(false);
            listGrupoOrigemFora.setEnabled(false);
            buttonInsereGrupoOrigem.setEnabled(false);
            buttonRemoveGrupoOrigem.setEnabled(false);
        }
    }//GEN-LAST:event_cbEmpresaOrigemActionPerformed

    private void buttonInsereGrupoOrigemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInsereGrupoOrigemActionPerformed
        removeEmpresaList1InsereList2(listGrupoOrigemFora, empresaOrigemFora, empresaOrigemDentro);
        updateEmpresaOrigemFora();
        updateEmpresaOrigemDentro();
    }//GEN-LAST:event_buttonInsereGrupoOrigemActionPerformed

    private void buttonRemoveGrupoOrigemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveGrupoOrigemActionPerformed
        removeEmpresaList1InsereList2(listGrupoOrigemDentro, empresaOrigemDentro, empresaOrigemFora);
        updateEmpresaOrigemFora();
        updateEmpresaOrigemDentro();
    }//GEN-LAST:event_buttonRemoveGrupoOrigemActionPerformed

    private void cbEmpresaDestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEmpresaDestinoActionPerformed
        if (cbEmpresaDestino.isSelected()) {
            listGrupoDestinoDentro.setEnabled(true);
            listGrupoDestinoFora.setEnabled(true);
            buttonInsereGrupoDestino.setEnabled(true);
            buttonRemoveGrupoDestino.setEnabled(true);
        } else {
            listGrupoDestinoDentro.setEnabled(false);
            listGrupoDestinoFora.setEnabled(false);
            buttonInsereGrupoDestino.setEnabled(false);
            buttonRemoveGrupoDestino.setEnabled(false);
        }
    }//GEN-LAST:event_cbEmpresaDestinoActionPerformed

    private void buttonInsereGrupoDestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInsereGrupoDestinoActionPerformed
        removeEmpresaList1InsereList2(listGrupoDestinoFora, empresaDestinoFora, empresaDestinoDentro);
        updateEmpresaDestinoFora();
        updateEmpresaDestinoDentro();
    }//GEN-LAST:event_buttonInsereGrupoDestinoActionPerformed

    private void buttonRemoveGrupoDestinoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRemoveGrupoDestinoActionPerformed
        removeEmpresaList1InsereList2(listGrupoDestinoDentro, empresaDestinoDentro, empresaDestinoFora);
        updateEmpresaDestinoFora();
        updateEmpresaDestinoDentro();
    }//GEN-LAST:event_buttonRemoveGrupoDestinoActionPerformed
    private Map<String, Empresa> empresaOrigemFora = new HashMap<String, Empresa>();
    private Map<String, Empresa> empresaOrigemDentro = new HashMap<String, Empresa>();
    private Map<String, Empresa> empresaDestinoFora = new HashMap<String, Empresa>();
    private Map<String, Empresa> empresaDestinoDentro = new HashMap<String, Empresa>();
    private Set<String> dddsDentro = new HashSet<String>();
    private Set<String> dddsFora = new HashSet<String>();
    private Map<String, Telefone> telefonesFora = new HashMap<String, Telefone>();
    private Map<String, Telefone> telefonesDentro = new HashMap<String, Telefone>();
    private Map<String, Telefone> destinoFora = new HashMap<String, Telefone>();
    private Map<String, Telefone> destinoDentro = new HashMap<String, Telefone>();
    private Set<String> tiposFora = new HashSet<String>();
    private Set<String> tiposDentro = new HashSet<String>();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupCelFixo;
    private javax.swing.JButton buttonInsereGrupoDestino;
    private javax.swing.JButton buttonInsereGrupoOrigem;
    private javax.swing.JButton buttonRemoveGrupoDestino;
    private javax.swing.JButton buttonRemoveGrupoOrigem;
    private javax.swing.JCheckBox cbEmpresaDestino;
    private javax.swing.JCheckBox cbEmpresaOrigem;
    private javax.swing.JCheckBox checkBoxCelFixo;
    private javax.swing.JComboBox comboBoxHoraDuracaoFim;
    private javax.swing.JComboBox comboBoxHoraDuracaoInicio;
    private javax.swing.JComboBox comboBoxHoraFim;
    private javax.swing.JComboBox comboBoxHoraInicio;
    private javax.swing.JComboBox comboBoxMinutoDuracaoFim;
    private javax.swing.JComboBox comboBoxMinutoDuracaoInicio;
    private javax.swing.JComboBox comboBoxMinutoFim;
    private javax.swing.JComboBox comboBoxMinutoInicio;
    private javax.swing.JComboBox comboBoxSegundoDuracaoFim;
    private javax.swing.JComboBox comboBoxSegundoDuracaoInicio;
    private javax.swing.JCheckBox dataCheckBox;
    private javax.swing.JCheckBox dddCheckBox;
    private javax.swing.JList dddsDentroJList;
    private javax.swing.JList dddsForaJList;
    private javax.swing.JCheckBox destinoCheckBox;
    private javax.swing.JList destinoDentroJList;
    private javax.swing.JList destinoForaJList;
    private javax.swing.JCheckBox duracaoCheckBox;
    private com.toedter.calendar.JDateChooser fimDateChooser;
    private javax.swing.JCheckBox horaCheckBox;
    private com.toedter.calendar.JDateChooser inicioDateChooser;
    private javax.swing.JButton insereDDDButton;
    private javax.swing.JButton insereDestinoButton;
    private javax.swing.JButton insereTelefoneButton;
    private javax.swing.JButton insereTipoButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane13;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JList listGrupoDestinoDentro;
    private javax.swing.JList listGrupoDestinoFora;
    private javax.swing.JList listGrupoOrigemDentro;
    private javax.swing.JList listGrupoOrigemFora;
    private javax.swing.JButton okButton;
    private javax.swing.JRadioButton radioCel;
    private javax.swing.JRadioButton radioFixo;
    private javax.swing.JButton removeDDDButton;
    private javax.swing.JButton removeDestinoButton;
    private javax.swing.JButton removeTelefoneButton;
    private javax.swing.JButton removeTipoButton;
    private javax.swing.JCheckBox telefoneCheckBox;
    private javax.swing.JList telefonesDentroJList;
    private javax.swing.JList telefonesForaJList;
    private javax.swing.JCheckBox tipoCheckBox;
    private javax.swing.JList tiposDentroJList;
    private javax.swing.JList tiposForaJList;
    // End of variables declaration//GEN-END:variables

    private long getDuracaoSegundos(int hora, int minuto, int segundo) {
        return ((hora * 60 * 60) + (minuto * 60) + segundo);
    }

    private void fillEmpresas() {

        List<Empresa> empresas = null;
        try {
            empresas = FramePrincipal.COMUNICABD.selectAllEmpresa("empresa");
        } catch (SQLException ex) {
            Logger.getLogger(ListaEmpresas.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }

        if (empresas == null || empresas.isEmpty()) {
            return;
        }

        for (Empresa empresa : empresas) {
            String empresaStr = "" + empresa.getId() + " - " + empresa.getNome();
            empresaOrigemFora.put(empresaStr, empresa);
            empresaDestinoFora.put(empresaStr, empresa);
        }

        updateEmpresaOrigemFora();
        updateEmpresaDestinoFora();
    }

    private void updateEmpresaOrigemFora() {
        ListModel model = new MapBasedListModel(empresaOrigemFora);
        listGrupoOrigemFora.setModel(model);
    }

    private void updateEmpresaDestinoFora() {
        ListModel model = new MapBasedListModel(empresaDestinoFora);
        listGrupoDestinoFora.setModel(model);
    }

    private void updateEmpresaOrigemDentro() {
        ListModel model = new MapBasedListModel(empresaOrigemDentro);
        listGrupoOrigemDentro.setModel(model);
    }

    private void updateEmpresaDestinoDentro() {
        ListModel model = new MapBasedListModel(empresaDestinoDentro);
        listGrupoDestinoDentro.setModel(model);
    }
}
